package com.ruoyi.backups.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.backups.domain.MysqlBacklog;
import com.ruoyi.backups.service.IMysqlBacklogService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * mysql数据备份日志Controller
 * 
 * @author ruoyi
 * @date 2024-09-06
 */
@RestController
@RequestMapping("/backups/backlog")
public class MysqlBacklogController extends BaseController
{
    @Autowired
    private IMysqlBacklogService mysqlBacklogService;

    /**
     * 查询mysql数据备份日志列表
     */
    @PreAuthorize("@ss.hasPermi('backups:backlog:list')")
    @GetMapping("/list")
    public TableDataInfo list(MysqlBacklog mysqlBacklog)
    {
        startPage();
        List<MysqlBacklog> list = mysqlBacklogService.selectMysqlBacklogList(mysqlBacklog);
        return getDataTable(list);
    }

    /**
     * 导出mysql数据备份日志列表
     */
    @PreAuthorize("@ss.hasPermi('backups:backlog:export')")
    @Log(title = "mysql数据备份日志", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MysqlBacklog mysqlBacklog)
    {
        List<MysqlBacklog> list = mysqlBacklogService.selectMysqlBacklogList(mysqlBacklog);
        ExcelUtil<MysqlBacklog> util = new ExcelUtil<MysqlBacklog>(MysqlBacklog.class);
        util.exportExcel(response, list, "mysql数据备份日志数据");
    }

    /**
     * 获取mysql数据备份日志详细信息
     */
    @PreAuthorize("@ss.hasPermi('backups:backlog:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(mysqlBacklogService.selectMysqlBacklogById(id));
    }

    /**
     * 新增mysql数据备份日志
     */
    @PreAuthorize("@ss.hasPermi('backups:backlog:add')")
    @Log(title = "mysql数据备份日志", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MysqlBacklog mysqlBacklog)
    {
        return toAjax(mysqlBacklogService.insertMysqlBacklog(mysqlBacklog));
    }

    /**
     * 修改mysql数据备份日志
     */
    @PreAuthorize("@ss.hasPermi('backups:backlog:edit')")
    @Log(title = "mysql数据备份日志", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MysqlBacklog mysqlBacklog)
    {
        return toAjax(mysqlBacklogService.updateMysqlBacklog(mysqlBacklog));
    }

    /**
     * 删除mysql数据备份日志
     */
    @PreAuthorize("@ss.hasPermi('backups:backlog:remove')")
    @Log(title = "mysql数据备份日志", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(mysqlBacklogService.deleteMysqlBacklogByIds(ids));
    }
}
